package single_;

/**
 * @author wly
 * @create 2022-12-03 10:56
 */
public class SingleTon01 {
    public static void main(String[] args) {
        GirlFriend instance = GirlFriend.getInstance();
        System.out.println(instance);
        GirlFriend g2 = GirlFriend.getInstance();
        System.out.println(g2);
        System.out.println(instance == g2);
    }
}

class GirlFriend{
    private String name;
    private static GirlFriend gf = new GirlFriend("小白");
    private GirlFriend(String name){
        this.name = name;
    }

    public static GirlFriend getInstance(){
        return gf;
    }

    @Override
    public String toString() {
        return "GirlFriend{" +
                "name='" + name + '\'' +
                '}';
    }
}